package com.example.controller;

import com.example.service.MqttService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/mqtt")
public class MqttController {

    @Autowired
    private MqttService mqttService;

    /**
     * 发布消息
     */
    @PostMapping("/publish")
    public String publishMessage(@RequestBody PublishRequest request) {
        mqttService.publishMessage(request.getTopic(), request.getMessage());
        return "消息发布成功";
    }

    /**
     * 健康检查
     */
    @GetMapping("/health")
    public String health() {
        return "MQTT服务运行正常";
    }

    @Data
    public static class PublishRequest {
        private String topic;
        private String message;
    }
} 